import axios from "axios";

const url = 'http://sinograin.otto.xin' // 线上地址

const url2 = 'http://192.168.111.26:7005' // 本地联调地址

const request = axios.create({
    baseURL: url,
    timeout: 50000,
})
import router from '../../../router/index'

request.interceptors.request.use(config=>{
    let token = localStorage.getItem("token")
    if(token) {
        config.headers.token = token
    }
    return config
}, err=>{
    return Promise.reject(err)
})

request.interceptors.response.use(res=>{
    const data = res.data;
    if(data.code==500) {
        router.push("/loginqiti")
        localStorage.removeItem("token")
        localStorage.removeItem('userIdqiti')
        localStorage.removeItem('deptName')
    }
    return data;
})

export default request